package com.fiveflavors.suittar.gui.mainpanel.view;

import java.net.URL;

import twitter4j.UserWithStatus;

import com.fiveflavors.suittar.SuittarCommand;
import com.fiveflavors.suittar.gui.utils.Converter;
import com.fiveflavors.suittar.resources.SuittarResourceManager;

public class SuittarFriendsTimeLineView extends SuittarTimeLineView {

	@Override
	public StringBuffer getHeaderContents(SuittarTimeLineViewBean suittarTimeLineViewBean) {
		StringBuffer buf = new StringBuffer();
		UserWithStatus user = suittarTimeLineViewBean.getSelectedUser();
		buf.append("<DIV ALIGN=\"RIGHT\">");
		if (user.getId() != suittarTimeLineViewBean.getMyUser().getId()) {
			URL closeURL = SuittarResourceManager.getResourceUrl(SuittarResourceManager.ICON_CLOSE);
			URL refreshURL = SuittarResourceManager.getResourceUrl(SuittarResourceManager.ICON_REFRESH);
			buf.append("<A HREF=\"http://suittar20/command?command=" + SuittarCommand.COMMAND_SHOW_FRIENDS + "&id=" + user.getId() + "&page=" + suittarTimeLineViewBean.getPage() + "\">");
			buf.append(Converter.convertURL2ImgTagHtml(refreshURL));
			buf.append("</A>&nbsp;");
			buf.append("<A HREF=\"http://suittar20/closepane?id=" + user.getId() + "\">");
			buf.append(Converter.convertURL2ImgTagHtml(closeURL));
			buf.append("</A>&nbsp;");
		}
		else {
			URL refreshURL = SuittarResourceManager.getResourceUrl(SuittarResourceManager.ICON_REFRESH);
			buf.append("<A HREF=\"http://suittar20/command?command=" + SuittarCommand.COMMAND_SHOW_FRIENDS + "&id=" + user.getScreenName() + "&page=" + suittarTimeLineViewBean.getPage() + "\">");
			buf.append(Converter.convertURL2ImgTagHtml(refreshURL));
			buf.append("</A>&nbsp;");
		}
		buf.append("</DIV>");
		return buf;
	}
	
	@Override
	public StringBuffer getFooterContents(SuittarTimeLineViewBean suittarTimeLineViewBean) {

		URL nextURL = SuittarResourceManager.getResourceUrl(SuittarResourceManager.ICON_NEXT);
		URL prevURL = SuittarResourceManager.getResourceUrl(SuittarResourceManager.ICON_PREV);
		URL prevDisableURL = SuittarResourceManager.getResourceUrl(SuittarResourceManager.ICON_PREV_DISABLE);

		String id = String.valueOf(suittarTimeLineViewBean.getSelectedUser().getId());
		int page = suittarTimeLineViewBean.getPage();
		
		StringBuffer buf = new StringBuffer();
		
		//TODO 現在、Friend Timelineのpageは一時的に使用中止になっている。
		buf.append("<HR WIDTH=\"100%\" SIZE=\"1\">");
		buf.append("<TABLE WIDTH=\"100%\">");
		buf.append("<TR ALIGN=\"RIGHT\">");
		buf.append("<TD>");
		if (page > 1) {
			buf.append("<A HREF=\"http://suittar20/command?command=" + SuittarCommand.COMMAND_SHOW_FRIENDS + "&id=" + id + "&page=" + (page - 1) + "\">");
			buf.append(Converter.convertURL2ImgTagHtml(prevURL));
			buf.append("</A>");
		}
		else {
			buf.append(Converter.convertURL2ImgTagHtml(prevDisableURL));
		}
		buf.append("&nbsp;&nbsp;");
		buf.append("<A HREF=\"http://suittar20/command?command=" + SuittarCommand.COMMAND_SHOW_FRIENDS + "&id=" + id + "&page=" + (page + 1) + "\">");
		buf.append(Converter.convertURL2ImgTagHtml(nextURL));
		buf.append("</A>");
		buf.append("</TD>");
		buf.append("</TR>");
		buf.append("</TABLE>");		

		return buf;
	}

	
}
